package com.mork.action.order;

import java.util.ArrayList;
import java.util.List;

import com.mock.dao.MemberDao;
import com.mock.dao.ProductDao;
import com.mock.dao.ProductTypeDao;
import com.mock.dao.UserDao;
import com.mock.dao.impl.MemberDaoImpl;
import com.mock.dao.impl.ProductDaoImpl;
import com.mock.dao.impl.ProductTypeDaoImpl;
import com.mock.dao.impl.UserDaoImpl;
import com.mock.model.Member;
import com.mock.model.OrderFood;
import com.mock.model.Product;
import com.mock.model.ProductType;
import com.mock.model.User;
import com.opensymphony.xwork2.ActionSupport;

public class DetailOrderAction extends ActionSupport{
	private ProductDao productDao = new ProductDaoImpl();
	private ProductTypeDao productTypeDao = new ProductTypeDaoImpl();
	private MemberDao memberDao = new MemberDaoImpl();
	private UserDao userDao = new UserDaoImpl();
	private List<ProductType> productTypes;
	private List<Product> products;
	private List<Member> members;
	private List<User> users;
	private int productTypeId;
	private OrderFood orderFood;
	
	private List<ArrayList<String>> productByTypeJson = new ArrayList<ArrayList<String>>();
	
	public String execute() {
		System.out.println("detail order");
		productTypes = productTypeDao.getAllProductType();
		products = new ArrayList<>();
		members = memberDao.getAllMember();
		users = userDao.getAllUser();
		orderFood = new OrderFood();
		return SUCCESS;
	}
	
	public String getProductByType(){
		productByTypeJson.clear();
		if(productTypeId > 0){
			ProductType productType = productTypeDao.getById(ProductType.class, (long) productTypeId);
			List<Product> allProduct = productDao.getAllProduct();
			if(allProduct != null && allProduct.size() > 0){
				for(int i = 0; i < allProduct.size(); i++){
					if (allProduct.get(i).getProductType().getId() == productType.getId()) {
						ArrayList<String> newArray = new ArrayList<String>();
						newArray.add(allProduct.get(i).getId().toString());
						newArray.add(allProduct.get(i).getName());
						productByTypeJson.add(newArray);
					}
				}
			}
		}
		return SUCCESS;
	}
	
	public List<ProductType> getProductTypes() {
		return productTypes;
	}
	public void setProductTypes(List<ProductType> productTypes) {
		this.productTypes = productTypes;
	}

	public List<Product> getProducts() {
		return products;
	}

	public void setProducts(List<Product> products) {
		this.products = products;
	}

	public int getProductTypeId() {
		return productTypeId;
	}

	public void setProductTypeId(int productTypeId) {
		this.productTypeId = productTypeId;
	}

	public List<ArrayList<String>> getProductByTypeJson() {
		return productByTypeJson;
	}

	public void setProductByTypeJson(List<ArrayList<String>> productByTypeJson) {
		this.productByTypeJson = productByTypeJson;
	}

	public List<Member> getMembers() {
		return members;
	}

	public void setMembers(List<Member> members) {
		this.members = members;
	}

	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	public OrderFood getOrderFood() {
		return orderFood;
	}

	public void setOrderFood(OrderFood orderFood) {
		this.orderFood = orderFood;
	}
}
